﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Plateformeur.GameEntities
{
    public class Gravity : Engine.MovableGameObject
    {
        Vector2 mGravity;

        public Gravity(Vector2 pDirection, float pSpeed,string pSpritePah,Vector2 pPositionInitiale)
            :base(pDirection,pSpeed,pSpritePah,pPositionInitiale,sContent,sGame)
        {
            mGravity = new Vector2(0, 50);
        }

        public override void Update(GameTime pTime)
        { 
            mVelocity += mGravity * (float)pTime.ElapsedGameTime.TotalSeconds;
            Vector2 lPosition = getNextPosition(pTime);
            Rectangle lRect = new Rectangle((int)lPosition.X, (int)lPosition.Y, mRenderedRect.Width, mRenderedRect.Height);
            foreach (Plateform plateform in Plateform.sPlateforms)
            {
                if (plateform.Intersect(lRect).mCollideInfo.mCollide)
                {
                    mVelocity.Y = 0.0f;
                }
            }
            base.Update(pTime);
        }
    }
}
